package thread.demo.threadPoolExecutor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorTest002 {
  public static void main(String[] args) {
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 3, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(1));
    
    for (int i = 0; i < 3; i++) {
      final int index = i;
      threadPoolExecutor.execute(() -> {
        try {
          TimeUnit.SECONDS.sleep(index + 1);
        } catch (InterruptedException e) {
          throw new RuntimeException(e);
        }
        
        System.out.println(Thread.currentThread().getName() + " : " + index);
      });
    }
  }
}
